package com.lfy.util;

import lombok.Data;

@Data
public class R {
    private static R r ;
    private Integer code;
    private String msg;
    private Object data;
    private R() {

    }
    public static R getR(){
        if(null == r){
            synchronized (R.class){
                if(null == r){
                    r = new R();
                }
            }
        }
        return r;
    }
    public static R SUCCESS(){
        R r = getR();
        r.setCode(Messages.LOGIN_SUCCESS.getCode());
        r.setMsg(Messages.LOGIN_SUCCESS.getMsg());
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return r;
    }
    public static R SUCCESS(Object object){
        R r = getR();
        r.setCode(Messages.LOGIN_SUCCESS.getCode());
        r.setMsg(Messages.LOGIN_SUCCESS.getMsg());
        r.setData(object);
        return r;
    }
    public static R ERROR(){
        R r = getR();
        r.setCode(Messages.LOGIN_ERROR.getCode());
        r.setMsg(Messages.LOGIN_ERROR.getMsg());

        return r;
    }
    public static R ERROR(Object object){
        R r = getR();
        r.setCode(Messages.LOGIN_ERROR.getCode());
        r.setMsg(Messages.LOGIN_ERROR.getMsg());
        r.setData(object);
        return r;
    }
}
